import React from 'react'
import localstore from '../util/localstore.js'
import {CITYNAME} from '../config/localstateKey.js'
import {bindActionCreators} from 'redux'
import {connect} from 'react-redux'
import * as Actions from '../actions/userinfo.js'
import {withRouter} from 'react-router-dom'

class App extends React.Component{
    constructor(props) {
        super(props)
        this.state = {
            initDone: false
        }
    }
    render() {
        return (
            <div>
                {
                    this.state.initDone?this.props.children : <p>加载中···· </p>
                }
            </div>
        )
    }

    componentDidMount() {
        let cityName = localstore.getItem(CITYNAME)
        if(cityName == null) {
            cityName = '北京'
        }

        this.props.userinfoActions.update({
            cityName: cityName
        })
        this.setState({
            initDone: true
        })
    }
}

function mapStateToProps(){
    return {

    }
}
function mapDispatchToProps(dispatch){
    return {
        userinfoActions: bindActionCreators(Actions, dispatch)
    }
}

export default withRouter(
    connect(
        mapStateToProps,
        mapDispatchToProps
    )(App)
)

// export default App